// pages/duty/allduty/allduty.js
var app = getApp()
var util = require('../../../utils/util.js')  
Page({

  /**
   * 页面的初始数据
   */
  data: {
    companyId:0,
    dutyTypeCode:'',
    year:'',
    feeds3:{},
    page:1
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that=this;
    // var feeds2 =options.feeds2;
    var companyId=options.companyId;
    var dutyTypeCode=options.dutyTypeCode;
    var year=options.year;
    that.data.companyId=companyId;
    that.data.dutyTypeCode = dutyTypeCode;
    that.data.year = year;
    console.log(that.data.companyId + that.data.dutyTypeCode + that.data.year);
    this.getFeeds3(that.data.page)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    wx.showLoading({
      title: '加载更多内容',
    })
    var that = this;
    this.getFeeds3(that.data.page);
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

/*所有值班详情*/
  getFeeds3: function (page) {
    if (page == 1) {
      wx.showLoading({
        title: '加载中',
      })
    }
    var header;
    header = {
      'Cookie': wx.getStorageSync("sessionid") //读取cookie
    };
    var that = this
    wx.request({
      url: app.globalData.baseUrl + '/safe/sysDuty/getDutyByType?pageCurrent	=' +
         page + '&companyId=' + that.data.companyId + '&dutyTypeCode='+that.data.dutyTypeCode+'&year='+that.data.year + '&pageSize=10',
      method: 'post',
      header: header,
      success: function (res) {
        wx.hideLoading();
        var res = res.data.data;
        console.log(res);
        // for (var item in res) {
        //   console.log(res[item].dutyList);
        // }
        for (var item in res) {
          for (var a = 0; a < res[item].dutyList.length; a++){
            var dateObj = new Date();
            dateObj.setTime(res[item].dutyList[a].dutyDate);
            res[item].dutyList[a].dutyDate = util.formatTime(dateObj);
            // console.log(res[item].dutyList[a].dutyDate);
            // res[item].dutyList[a].dutyDate = util.formatTime(res[item].dutyList[a].dutyDate, 'Y/M/D');
            // console.log(res[item].dutyList[a].dutyDate);
          }
        }
        // console.log(res);
        if (that.data.page > 1) {
          var feedTemp = that.data.feeds3;
          that.setData({
            feeds3: Object.assign(feedTemp, res),
            page: page + 1
          });
        } else {
          that.setData({
            feeds3: res,
            page: page + 1
          })
        }
      }
    })
  },

})